/**
 * 是否是外链
 * @param path
 * @returns
 */
export function isExternal(path: string) {
  return /^(https?:|mailto:|tel:)/.test(path);
}

/**
 * 是否拥有角色
 * @param myRole 
 * @param roleList 
 * @param mode 
 * @returns 
 */
export function hasRole(myRole: Array<string>, roleList: Array<string>, mode: string): boolean {
  if (!roleList) {
    if (!["and", "or"].includes(mode)) {
      console.error("不支持该模式：", mode);
      return false;
    }
    return true;
  }
  switch (mode) {
    case "and":
      let hasCount: number = 0;
      if (myRole.length !== roleList.length) {
        return false;
      }
      for (const role of myRole) {
        roleList.includes(role) ? hasCount++ : "";
      }
      if (hasCount === myRole.length) {
        return true;
      }
      return false;
    case "or":
      for (const role of myRole) {
        if (roleList.includes(role)) {
          return true;
        }
      }
      return false;
    default:
      console.error("不支持该模式：", mode);
      return false;
  }
}
